import axios from '@/libs/api.request'
import qs from "qs";
// 角色

// 获取角色列表
export const getRoles = (params) => {
  return axios.request({
      url: '/user/role',
      method: 'get',
      params
  })
}

//获取角色信息
export const getRole = (roleId)=>{
  return axios.request({
      url:`user/role/${roleId}`,
      method:'get'
  })
}

// 新增角色
export const addRole = (params)=>{
  return axios.request({
      url:`user/role`,
      method:'post',
      data:qs.stringify(params)
  })
}

//编辑角色
export const editRole = (params,roleId)=>{
  return axios.request({
      url:`user/role/${roleId}`,
      method:'put',
      data:qs.stringify(params)
  })
}

//删除角色
export const deleteRole = (roleId) => {
  return axios.request({
      url: `/user/role/${roleId}`,
      method: 'delete'
  })
}

//添加角色的用户
export const addRoleUser = (roleId,params)=>{
  return axios.request({
      url:`/user/role/${roleId}/user`,
      method:'post',
      data:qs.stringify(params)
  })
}

//删除角色用户
export const deleteRoleUser = (roleId,userId) => {
  return axios.request({
      url: `/user/role/${roleId}/user/${userId}`,
      method: 'delete'
  })
}

// 获取管理员角色权限
export const getCompanyAdminAuth = ()=>{
  return axios.request({
      url:'/user/role/manager/tree',
      method:'options',
  })
}

// 获取角色的用户
export const getRoleUser = (roleId,params)=>{
  return axios.request({
      url:`/user/role/${roleId}/user`,
      method:'get',
      params:params
  })
}